#include "imInterfaces.h"
#include "Imagine.h"

std::list<iComponent*> g_Comps;
std::list<iEntity*> g_Ents;

using std::string;

using namespace imGraphics;

GraphicsComponent::GraphicsComponent() {
	m_Material = new Material();

	//iTexture* t = g_GFX->GetNewTexture();
	//t->FillSolid(Vector4(0.5f, 0.5f, 1.0f, 1.0f));
	//t->LoadFromFile(string("mclarenf1.bmp"));

	//m_Material->SetTexture(t, 0);
	m_Material->SetTexture(string("mclarenf1.bmp"), 0);
	//m_Mesh = new Mesh("mclarenf1.sms");
}

void GraphicsComponent::SetMesh(Mesh* NewMesh) {
	m_Mesh = NewMesh;
}

void GraphicsComponent::SetMaterial(Material *NewMaterial) {
	m_Material = NewMaterial;
}

void GraphicsComponent::Update() {
	m_Pos = m_Owner->GetPos();
	m_Orientation = m_Owner->GetOrientation();

	g_GFX->SetWorldMatrix(Matrix::World(*m_Pos, *m_Orientation));

	m_Material->StartRender();
	m_Mesh->Predraw();
	m_Mesh->Draw(0);
	m_Material->EndRender();
}